package com.night.student.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Mr.Wang
 * @ClassName: RabbitConfig
 * @Description: //TODO
 * @date: 2022/10/22-21:09
 */
@Configuration
public class RabbitConfig {
    //声明交换机
    @Bean
    public TopicExchange exchangeTopic(){
        return new TopicExchange("exchangetopic");
    }

    //声明队列
    @Bean
    public Queue queueCourse(){
        return new Queue("queueCourse");
    }

    //绑定队列到交换机
    @Bean
    public Binding bindingCourse(){
        return BindingBuilder.bind(queueCourse()).to(exchangeTopic()).with("afterselect");
    }


    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }
}
